import { Injectable  } from '@angular/core';
import { EventEmitter } from 'eventemitter3';



@Injectable({
  providedIn: 'root'
})
export class EventService {

  public event:any;

  constructor() {
    this.event=new EventEmitter();   //这个实例就会被多个组件共享  来实现不同页面的数据通信
  }

  emit(eventKey: string, ...args: any[]) {
    this.event.emit(eventKey, args);
  }
  
  addListener(eventKey: string, handler: (...args: any[]) => void) {
    this.event.addListener(eventKey, handler);
  }

}
